<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   【译文】深度学习R（1）：从零开始建立完全连接的神经网络  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/22141.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466457373: Accept with keywords: (title(0.4):神经网络,社区,数盟,译文,深度学习, topn(0.566666666667):初始化,社区,数盟,深度学习,行业资讯,神经网络,预测,架构,特征,模型,可视化,译文,文章,数据,节点,偏差,函数,权重,回归,矩阵,篇文章,乘法,编程语言,方法,代码,分类,网络,损失,单元,神经元).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    【译文】深度学习R（1）：从零开始建立完全连接的神经网络
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    【译文】深度学习R（1）：从零开始建立完全连接的神经网络 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,75] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech/devl">
       编程语言
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/22141.html">
          【译文】深度学习R（1）：从零开始建立完全连接的神经网络
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          1,940 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech/devl" rel="category tag">
          编程语言
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        <span style="color: #800000;">
         <strong>
          本文为数盟原创译文，欢迎转载，注明出处“数盟社区”即可
         </strong>
        </span>
       </p>
       <p>
        作者：PENG ZHAO
       </p>
       <p>
        我要感谢Feiwen, Neil和所有其他的技术评论家和读者，他们为本文提出了宝贵的意见和建议。
       </p>
       <p>
        背景
       </p>
       <p>
        深度神经网络（DNN）近年来取得了在图像识别、自然语言处理和自动驾驶领域取得了巨大成就，如图1所示，从2012至2015年IMAGNET的识别准确度由80%以内提高到95%以内，这远远超过了传统的计算机视觉识别（CV）方法。
       </p>
       <p>
        <img src="http://www.parallelr.com/wp-content/uploads/2016/02/ces2016.png"/>
       </p>
       <p style="text-align: center;">
        图1 –  来自NVIDIA CEO 黄仁勋在2016年国际消费类电子产品展览会上的演讲
       </p>
       <p>
       </p>
       <p>
        在这篇文章中，我们将关注于完全连接的神经网络——通常在数据科学中被称为DNN。DNN的最大优点是能够通过深层结构自动提取和学习特征，尤其是对这些工程师不能轻易捕捉到的复杂高维特征的数据，例如Kaggle。因此，DNN也对数据科学家很有吸引力，有许多成功案例，如分类、时间序列和推荐系统，如Nick的文章和DNN信用评分。在CRAN和R的社区，有几个比较成熟的DNN包，包括神经网络，nerualnet，H2O，DARCH，deepnet和mxnet，我强烈推荐《
        <a href="http://www.h2o.ai/verticals/algos/deep-learning/">
         H2O DNN algorithm and R interface
        </a>
        》。
       </p>
       <p>
       </p>
       <p>
        那么，
        <strong>
         我们到底如何从头开始建立DNN呢？
        </strong>
       </p>
       <p>
        -理解神经网络是如何工作的
       </p>
       <p>
        利用现有的DNN的包，在大多数时候您建立DNN模型只需要一行R代码，而且还有神经网络实例。但对于没有经验的用户，处理过程和结果可能是难以理解的。因此，它将是一个有价值的实践，有助于您完善自己的网络以便于从结构和算法的角度了解更多的细节。
       </p>
       <p>
        -用你的新想法建立特定的网络
       </p>
       <p>
        DNN是一个迅速发展的领域。每周都会有大量的新发现和研究成果发表在顶级期刊和互联网上。DNN用户也有其特定的神经网络结构以针对他们的问题，例如不同的激活、损失函数、正规化和连通图的问题。另一方面，新的研究成果出来之前，几乎所有现有的包都是用C/C++，Java写的，所以它们不能适用于一些最新升级，也不能通过修改把你的思维加进去。
       </p>
       <p>
        -网络和数据的训练和可视化
       </p>
       <p>
        正如我们提到的，现有的DNN包是高度集中的，并且是一些低等级语言编写的，所以我们需要逐层或逐节点训练网络，这是一场噩梦。即使是不容易在每一层中将结果可视化，监视数据或权重在训练中一直是变化的，并显示在网络中发现的模式。
       </p>
       <p>
       </p>
       <p>
        <strong>
         基本概念和组成部分
        </strong>
       </p>
       <p>
        完全连接神经网络，在数据科学中称为DNN，是相邻的网络层是完全相互连接。网络中的每个神经元都与相邻层中的每一个神经元相连。
       </p>
       <p>
        如下图所示是一个非常简单的和典型的神经网络，有1个输入层，2个隐藏层，和1个输出层。最主要的是，当研究人员谈论网络的体系结构时，它指的是DNN的配置，如整个网络有多少层，每层有多少神经元，正在应用什么类型的激活、损失函数、正则化。
       </p>
       <p>
        <img src="http://www.parallelr.com/wp-content/uploads/2016/02/dnn_architecture.png"/>
       </p>
       <p>
        现在，我们将通过DNN的基本组件，向你展示它如何在R中实现。
       </p>
       <p>
       </p>
       <p>
        <strong>
         权重和偏差值
        </strong>
       </p>
       <p>
        以上述DNN架构为例，从输入层到第一隐藏层、第一到第二隐藏层、第二隐藏层到输出层有3组权重。偏差单元连接到每个隐藏节点并影响着输出分数，但不与实际数据进行接触。在我们的R研究中，我们通过矩阵展示了权重和偏差。权重大小的计算公式是：
       </p>
       <p>
        (神经元层数 M) X (每层中的神经元数量 M+1)
       </p>
       <p>
        并且权重值通过rnorm公式的随机数而被初始化。偏差值只是一个一维矩阵，和神经元相同大小，并且值被设定为0。其他的初始化方法，如校准1 / sqrt（N）和稀疏初始化的差异，在斯坦福大学CS231n的
        <a href="http://cs231n.github.io/neural-networks-2/#init">
         weight initialization
        </a>
        部分中介绍过。
       </p>
       <p>
        其R代码为：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def38496880380" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          weight.i &lt;- 0.01*matrix(rnorm(layer.size(i)*layer.size(i+1), sd=0.5),
                        nrow=layer.size(i),
                        ncol=layer.size(i+1))
bias.i    &lt;- matrix(0, nrow=1, ncol = layer.size(i))
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def38496880380-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def38496880380-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def38496880380-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def38496880380-4">
               4
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def38496880380-1">
               <span class="crayon-v">
                weight
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.01
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                rnorm
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                sd
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                0.5
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def38496880380-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def38496880380-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def38496880380-4">
               <span class="crayon-v">
                bias
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-i">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0133 seconds] -->
       <p>
        另一种常见的实现方法，将权重和偏差值结合起来，使输入的维数是N+1，表明N输入特征偏差值为1，如下面的代码：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def4b561859653" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          weight   &lt;- 0.01*matrix(rnorm((layer.size(i)+1)*layer.size(i+1), sd=0.5),
                        nrow=layer.size(i)+1,
                        ncol=layer.size(i+1))
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def4b561859653-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def4b561859653-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def4b561859653-3">
               3
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def4b561859653-1">
               <span class="crayon-v">
                weight
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.01
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                rnorm
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                sd
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                0.5
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def4b561859653-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def4b561859653-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                size
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0126 seconds] -->
       <p>
        <strong>
         神经元
        </strong>
       </p>
       <p>
        神经元是DNN的基本单位，它是人类神经元的仿生模型。一个独立的神经元扮演着权重，并且输入乘法和加法（FMA），这和数据科学中的线性回归是一样的，然后FMA的结果传递给激活函数。
       </p>
       <p>
        常用的激活函数包括sigmoid、ReLu、Tanh和Maxout。在这篇文章中，我将采取纠正线性单元（ReLu）作为激活函数，f（x）= max（0，x）。对于其他类型的激活功能，您可以参考
        <a href="http://cs231n.github.io/neural-networks-1/#actfun">
         这里
        </a>
        。
       </p>
       <p>
        <img src="http://www.parallelr.com/wp-content/uploads/2016/02/neuron.png"/>
       </p>
       <p>
        在R中，我们可以通过多种方法操作神经元，比如sum(xi*wi)。但是通过矩阵乘法能够更有效的实现。
       </p>
       <p>
        其R代码为：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def53753191209" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          neuron.ij &lt;- max(0, input %*% weight + bias)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def53753191209-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def53753191209-1">
               <span class="crayon-v">
                neuron
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                ij
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                max
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                weight
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                bias
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0013 seconds] -->
       <p>
        <em>
         <strong>
          实施提示
         </strong>
        </em>
       </p>
       <p>
        在实践中，我们为了性能考虑总是以一批实例去更新一层中的所有神经元。因此，上述代码将无法正常工作。
       </p>
       <p>
        <em>
         1）矩阵乘法和加法
        </em>
       </p>
       <p>
        如以下代码所示，
        <em>
         input %*% weights
        </em>
        和
        <em>
         bias
        </em>
        是不同的
        <em>
         dimension
        </em>
        ，也不能直接被添加。这里提供两种解决方案。第一种重复bias的ncol次数。但是，它会在大量数据输入时浪费很多存储空间，因此，第二种方案更好
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def6e860846287" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          # dimension: 2X2
input &lt;- matrix(1:4, nrow=2, ncol=2)
# dimension: 2x3
weights &lt;- matrix(1:6, nrow=2, ncol=3)
# dimension: 1*3
bias &lt;- matrix(1:3, nrow=1, ncol=3)
# doesn't work since unmatched dimension
input %*% weights + bias
Error input %*% weights + bias : non-conformable arrays 
 
# solution 1: repeat bias aligned to 2X3 
s1 &lt;- input %*% weights + matrix(rep(bias, each=2), ncol=3) 
 
# solution 2: sweep addition
s2 &lt;- sweep(input %*% weights ,2, bias, '+')
 
all.equal(s1, s2)
[1] TRUE
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def6e860846287-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def6e860846287-18">
               18
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def6e860846287-1">
               <span class="crayon-p">
                # dimension: 2X2
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-2">
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                4
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-3">
               <span class="crayon-p">
                # dimension: 2x3
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-4">
               <span class="crayon-v">
                weights
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-5">
               <span class="crayon-p">
                # dimension: 1*3
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-6">
               <span class="crayon-v">
                bias
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-7">
               <span class="crayon-p">
                # doesn't work since unmatched dimension
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-8">
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                weights
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                bias
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-9">
               <span class="crayon-e">
                Error
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                weights
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                bias
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                non
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-e">
                conformable
               </span>
               <span class="crayon-i">
                arrays
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-10">
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-11">
               <span class="crayon-p">
                # solution 1: repeat bias aligned to 2X3
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-12">
               <span class="crayon-v">
                s1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                weights
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                rep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                bias
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                each
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-13">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-14">
               <span class="crayon-p">
                # solution 2: sweep addition
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-15">
               <span class="crayon-v">
                s2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sweep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                weights
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                bias
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '+'
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-16">
              </div>
              <div class="crayon-line" id="crayon-57685d16def6e860846287-17">
               <span class="crayon-v">
                all
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                equal
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                s1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                s2
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def6e860846287-18">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                TRUE
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0255 seconds] -->
       <p>
        <em>
         2）一个矩阵的元素级最大值
        </em>
       </p>
       <p>
        另一个小方法就是通过pmax代替max来获得元素级最大值而不是一个全程的值，注意pmax里的顺序。
        <em>
         <img src="http://www.parallelr.com/wp-includes/images/smilies/simple-smile.png"/>
        </em>
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def77791361447" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          # the original matrix
&gt; s1
     [,1] [,2] [,3]
[1,]    8   17   26
[2,]   11   24   37
 
# max returns global maximum 
&gt; max(0, s1)
[1] 37
 
# s1 is aligned with a scalar, so the matrix structure is lost
&gt; pmax(0, s1)
[1]  8 11 17 24 26 37
 
# correct 
# put matrix in the first, the scalar will be recycled to match matrix structure
&gt; pmax(s1, 0)
     [,1] [,2] [,3]
[1,]    8   17   26
[2,]   11   24   37
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def77791361447-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def77791361447-20">
               20
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def77791361447-1">
               <span class="crayon-c">
                # the original matrix
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-2">
               <span class="crayon-o">
                &gt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                s1
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-4">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                8
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                17
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                26
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-5">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                11
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                24
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                37
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-6">
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-7">
               <span class="crayon-c">
                # max returns global maximum
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-8">
               <span class="crayon-o">
                &gt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                max
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                s1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-9">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                37
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-10">
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-11">
               <span class="crayon-c">
                # s1 is aligned with a scalar, so the matrix structure is lost
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-12">
               <span class="crayon-o">
                &gt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pmax
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                s1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-13">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                8
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                11
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                17
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                24
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                26
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                37
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-14">
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-15">
               <span class="crayon-c">
                # correct
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-16">
               <span class="crayon-c">
                # put matrix in the first, the scalar will be recycled to match matrix structure
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-17">
               <span class="crayon-o">
                &gt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pmax
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                s1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def77791361447-19">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                8
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                17
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                26
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def77791361447-20">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                11
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                24
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                37
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0138 seconds] -->
       <p>
        <strong>
         层
        </strong>
       </p>
       <p>
        -输入层
       </p>
       <p>
        输入层是相对固定的，只有1层，其数字单位相当于输入数据的特征数量。
       </p>
       <p>
        -隐藏层
       </p>
       <p>
        隐藏层种类很多，是DNN的核心部件。但在一般情况下，需要更多的隐藏层捕捉请求的模式，以解决更复杂的问题（非线性）。
       </p>
       <p>
        -输出层
       </p>
       <p>
        在输出层中的单元通常没有激活，因为它通常是在分类中表示类的分数和回归中的任意实数值。对于分类，输出单元的数目与预测的类别数相匹配，而只有一个输出节点进行回归。
       </p>
       <p>
       </p>
       <p>
        <strong>
         构建神经网络：体系结构、预测和训练
        </strong>
       </p>
       <p>
        到目前为止，我们已经了解了深层神经网络的基本概念，我们将建立一个神经网络，其中包括确定网络体系结构，训练网络，然后预测新的数据与学习网络。为了简化步骤，我们使用一个小的数据集——埃德加安德森的虹膜数据（IRIS），通过DNN做分类。
       </p>
       <p>
        <strong>
         网络架构
        </strong>
       </p>
       <p>
        IRIS是众所周知的内置数据集，在机器学习的存量的R中。所以你可以直接通过下面的控制台总结来了解这个资料组。
       </p>
       <p>
        其R代码为：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def80880657737" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          summary(iris)
  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width          Species  
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100   setosa    :50  
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300   versicolor:50  
 Median :5.800   Median :3.000   Median :4.350   Median :1.300   virginica :50  
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199                  
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800                  
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def80880657737-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def80880657737-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def80880657737-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def80880657737-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def80880657737-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def80880657737-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def80880657737-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def80880657737-8">
               8
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def80880657737-1">
               <span class="crayon-e">
                summary
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def80880657737-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Sepal
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                Length
               </span>
               <span class="crayon-v">
                Sepal
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                Width
               </span>
               <span class="crayon-v">
                Petal
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                Length
               </span>
               <span class="crayon-v">
                Petal
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                Width
               </span>
               <span class="crayon-e">
                Species
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def80880657737-3">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                Min
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                4.300
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Min
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                2.000
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Min
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                1.000
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Min
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                0.100
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                setosa
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def80880657737-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1st
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                5.100
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1st
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                2.800
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1st
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                1.600
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1st
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                0.300
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                versicolor
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def80880657737-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Median
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                5.800
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Median
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3.000
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Median
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                4.350
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Median
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                1.300
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                virginica
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def80880657737-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Mean
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                5.843
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Mean
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3.057
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Mean
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3.758
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Mean
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                1.199
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def80880657737-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3rd
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                6.400
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3rd
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3.300
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3rd
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                5.100
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3rd
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Qu
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                1.800
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def80880657737-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Max
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                7.900
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Max
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                4.400
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Max
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                6.900
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Max
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                2.500
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0214 seconds] -->
       <p>
        概要里有四个特征和三个类别的Species。所以我们可以设计一个DNN架构如下。
       </p>
       <p>
        <img src="http://www.parallelr.com/wp-content/uploads/2016/02/iris_network.png"/>
       </p>
       <p>
        然后，我们将我们的DNN模型保存在一个列表里，可用于培训或预测，如下。实际上，我们可以在模型中保留更多的感兴趣的参数，这具有很大的灵活性。
       </p>
       <p>
        其R代码为：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def87857332768" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          str(ir.model)
List of 7
 $ D : int 4
 $ H : num 6
 $ K : int 3
 $ W1: num [1:4, 1:6] 1.34994 1.11369 -0.57346 -1.12123 -0.00107 ...
 $ b1: num [1, 1:6] 1.336621 -0.509689 -0.000277 -0.473194 0 ...
 $ W2: num [1:6, 1:3] 1.31464 -0.92211 -0.00574 -0.82909 0.00312 ...
 $ b2: num [1, 1:3] 0.581 0.506 -1.088
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def87857332768-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def87857332768-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def87857332768-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def87857332768-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def87857332768-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def87857332768-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def87857332768-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def87857332768-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def87857332768-9">
               9
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def87857332768-1">
               <span class="crayon-e">
                str
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                ir
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def87857332768-2">
               <span class="crayon-e">
                List
               </span>
               <span class="crayon-i">
                of
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                7
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def87857332768-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                int
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                4
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def87857332768-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                num
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                6
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def87857332768-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                int
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def87857332768-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                num
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                4
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1.34994
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1.11369
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.57346
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1.12123
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.00107
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def87857332768-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                num
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1.336621
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.509689
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.000277
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.473194
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def87857332768-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                num
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1.31464
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.92211
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.00574
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.82909
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.00312
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def87857332768-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                num
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.581
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.506
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1.088
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0296 seconds] -->
       <p>
        <strong>
         预测
        </strong>
       </p>
       <p>
        预测，也被称为机器学习领域的分类或推理，比测试更为简洁，它通过矩阵乘法，从输入到输出来逐层穿越网络层。在输出层，不需要激活功能。在分类上，概率将由SOFTMAX进行计算而在回归上，输出代表实际的值的预测。这个过程被称为前馈或反馈传播。
       </p>
       <p>
        其R代码为：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def8e882733813" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          # Prediction
predict &lt;- function(model, data = X.test) {
  # new data, transfer to matrix
  new.data &lt;- data.matrix(data)

  # Feed Forwad
  hidden.layer &lt;- sweep(new.data %*% model$W1 ,2, model$b1, '+')
  # neurons : Rectified Linear
  hidden.layer &lt;- pmax(hidden.layer, 0)
  score &lt;- sweep(hidden.layer %*% model$W2, 2, model$b2, '+')

  # Loss Function: softmax
  score.exp &lt;- exp(score)
  probs &lt;-sweep(score.exp, 1, rowSums(score.exp), '/') 

  # select max possiblity
  labels.predicted &lt;- max.col(probs)
  return(labels.predicted)
}
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def8e882733813-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def8e882733813-19">
               19
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def8e882733813-1">
               <span class="crayon-c">
                # Prediction
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-2">
               <span class="crayon-v">
                predict
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                test
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # new data, transfer to matrix
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                new
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-5">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # Feed Forwad
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sweep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-r">
                new
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-i">
                W1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '+'
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # neurons : Rectified Linear
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pmax
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sweep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '+'
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-11">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # Loss Function: softmax
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                exp
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                exp
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-14">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                probs
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-e">
                sweep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                exp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                rowSums
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                exp
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '/'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-15">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-16">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # select max possiblity
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-17">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                predicted
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                max
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                col
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                probs
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def8e882733813-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                predicted
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def8e882733813-19">
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0433 seconds] -->
       <p>
        <strong>
         训练
        </strong>
       </p>
       <p>
        训练是在既定的网络体系结构下，搜索优化参数（权重和偏差），并将分类错误或差值最小化。这个过程包括两个部分：前馈和反向传播。前馈是通过输入数据（如预测部分），通过网络，然后计算数据损失的输出层的损失函数（成本函数）。“数据损失度量预测（例如分类中的分类）和地面实况标签之间的相容性。”在我们的示例代码中，我们选择交叉熵函数来评估数据损失，点击
        <a href="http://cs231n.github.io/neural-networks-2/#losses">
         这里
        </a>
        查看。
       </p>
       <p>
        在获取数据丢失后，我们需要通过改变权重和偏差来减少数据丢失。通常流行的方法是通过梯度下降或随机梯度下降的损失，这需要每个数据损失的参数的倒数(W1, W2, b1, b2)。反馈会根据不同的激活功能而不同，这是他们的导数公式。这里是
        <a href="http://cs231n.github.io/neural-networks-3/">
         斯坦福大学CS231N
        </a>
        的更多的训练技巧。
       </p>
       <p>
        在我们的例子中，RELU逐点导数是：
       </p>
       <p>
        <img src="http://www.parallelr.com/wp-content/uploads/2016/02/class.relu_.png"/>
       </p>
       <p>
        其R代码为：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16def95580327420" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          # Train: build and train a 2-layers neural network 
train.dnn &lt;- function(x, y, traindata=data, testdata=NULL,
                  # set hidden layers and neurons
                  # currently, only support 1 hidden layer
                  hidden=c(6), 
                  # max iteration steps
                  maxit=2000,
                  # delta loss 
                  abstol=1e-2,
                  # learning rate
                  lr = 1e-2,
                  # regularization rate
                  reg = 1e-3,
                  # show results every 'display' step
                  display = 100,
                  random.seed = 1)
{
  # to make the case reproducible.
  set.seed(random.seed)

  # total number of training set
  N &lt;- nrow(traindata)

  # extract the data and label
  # don't need atribute 
  X &lt;- unname(data.matrix(traindata[,x]))
  Y &lt;- traindata[,y]
  if(is.factor(Y)) { Y &lt;- as.integer(Y) }
  # create index for both row and col
  Y.index &lt;- cbind(1:N, Y)

  # number of input features
  D &lt;- ncol(X)
  # number of categories for classification
  K &lt;- length(unique(Y))
  H &lt;-  hidden

  # create and init weights and bias 
  W1 &lt;- 0.01*matrix(rnorm(D*H, sd=0.5), nrow=D, ncol=H)
  b1 &lt;- matrix(0, nrow=1, ncol=H)

  W2 &lt;- 0.01*matrix(rnorm(H*K, sd=0.5), nrow=H, ncol=K)
  b2 &lt;- matrix(0, nrow=1, ncol=K)

  # use all train data to update weights since it's a small dataset
  batchsize &lt;- N

  # Training the network
  i &lt;- 0
  while(i &lt; maxit || loss &lt; abstol ) {

    # iteration index
    i &lt;- i +1

    # forward ....
    # 1 indicate row, 2 indicate col
    hidden.layer &lt;- sweep(X %*% W1 ,2, b1, '+')
    # neurons : ReLU
    hidden.layer &lt;- pmax(hidden.layer, 0)
    score &lt;- sweep(hidden.layer %*% W2, 2, b2, '+')

    # softmax
    score.exp &lt;- exp(score)
    probs &lt;-sweep(score.exp, 1, rowSums(score.exp), '/') 

    # compute the loss
    corect.logprobs &lt;- -log(probs[Y.index])
    data.loss  &lt;- sum(corect.logprobs)/batchsize
    reg.loss   &lt;- 0.5*reg* (sum(W1*W1) + sum(W2*W2))
    loss &lt;- data.loss + reg.loss

    # display results and update model
    if( i %% display == 0) {
        if(!is.null(testdata)) {
            model &lt;- list( D = D,
                           H = H,
                           K = K,
                           # weights and bias
                           W1 = W1, 
                           b1 = b1, 
                           W2 = W2, 
                           b2 = b2)
            labs &lt;- predict.dnn(model, testdata[,-y])
            accuracy &lt;- mean(as.integer(testdata[,y]) == labs)
            cat(i, loss, accuracy, "\n")
        } else {
            cat(i, loss, "\n")
        }
    }

    # backward ....
    dscores &lt;- probs
    dscores[Y.index] &lt;- dscores[Y.index] -1
    dscores &lt;- dscores / batchsize

    dW2 &lt;- t(hidden.layer) %*% dscores 
    db2 &lt;- colSums(dscores)

    dhidden &lt;- dscores %*% t(W2)
    dhidden[hidden.layer &lt;= 0] &lt;- 0

    dW1 &lt;- t(X) %*% dhidden
    db1 &lt;- colSums(dhidden) 

    # update ....
    dW2 &lt;- dW2 + reg*W2
    dW1 &lt;- dW1  + reg*W1

    W1 &lt;- W1 - lr * dW1
    b1 &lt;- b1 - lr * db1

    W2 &lt;- W2 - lr * dW2
    b2 &lt;- b2 - lr * db2

  }

  # final results
  # creat list to store learned parameters
  # you can add more parameters for debug and visualization
  # such as residuals, fitted.values ...
  model &lt;- list( D = D,
                 H = H,
                 K = K,
                 # weights and bias
                 W1= W1, 
                 b1= b1, 
                 W2= W2, 
                 b2= b2)

  return(model)
}
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-22">
               22
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-23">
               23
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-24">
               24
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-25">
               25
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-26">
               26
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-27">
               27
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-28">
               28
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-29">
               29
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-30">
               30
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-31">
               31
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-32">
               32
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-33">
               33
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-34">
               34
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-35">
               35
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-36">
               36
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-37">
               37
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-38">
               38
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-39">
               39
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-40">
               40
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-41">
               41
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-42">
               42
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-43">
               43
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-44">
               44
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-45">
               45
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-46">
               46
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-47">
               47
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-48">
               48
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-49">
               49
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-50">
               50
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-51">
               51
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-52">
               52
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-53">
               53
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-54">
               54
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-55">
               55
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-56">
               56
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-57">
               57
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-58">
               58
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-59">
               59
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-60">
               60
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-61">
               61
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-62">
               62
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-63">
               63
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-64">
               64
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-65">
               65
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-66">
               66
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-67">
               67
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-68">
               68
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-69">
               69
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-70">
               70
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-71">
               71
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-72">
               72
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-73">
               73
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-74">
               74
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-75">
               75
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-76">
               76
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-77">
               77
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-78">
               78
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-79">
               79
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-80">
               80
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-81">
               81
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-82">
               82
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-83">
               83
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-84">
               84
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-85">
               85
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-86">
               86
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-87">
               87
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-88">
               88
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-89">
               89
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-90">
               90
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-91">
               91
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-92">
               92
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-93">
               93
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-94">
               94
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-95">
               95
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-96">
               96
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-97">
               97
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-98">
               98
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-99">
               99
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-100">
               100
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-101">
               101
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-102">
               102
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-103">
               103
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-104">
               104
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-105">
               105
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-106">
               106
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-107">
               107
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-108">
               108
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-109">
               109
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-110">
               110
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-111">
               111
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-112">
               112
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-113">
               113
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-114">
               114
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-115">
               115
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-116">
               116
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-117">
               117
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-118">
               118
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-119">
               119
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-120">
               120
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-121">
               121
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-122">
               122
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-123">
               123
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-124">
               124
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-125">
               125
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-126">
               126
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-127">
               127
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-128">
               128
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-129">
               129
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16def95580327420-130">
               130
              </div>
              <div class="crayon-num" data-line="crayon-57685d16def95580327420-131">
               131
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16def95580327420-1">
               <span class="crayon-c">
                # Train: build and train a 2-layers neural network
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-2">
               <span class="crayon-v">
                train
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                dnn
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                traindata
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                testdata
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-t">
                NULL
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # set hidden layers and neurons
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # currently, only support 1 hidden layer
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-e">
                c
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # max iteration steps
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                maxit
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                2000
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # delta loss
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                abstol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                1e
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # learning rate
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                lr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1e
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # regularization rate
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                reg
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1e
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-14">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # show results every 'display' step
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-15">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                display
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                100
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-16">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                random
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                seed
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-17">
               <span class="crayon-sy">
                {
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # to make the case reproducible.
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-19">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                set
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                seed
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                random
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                seed
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-20">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-21">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # total number of training set
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-22">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                N
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                nrow
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                traindata
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-23">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-24">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # extract the data and label
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-25">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # don't need atribute
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-26">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                unname
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                traindata
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-27">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                traindata
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-28">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-st">
                is
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                factor
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                as
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-t">
                integer
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-29">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # create index for both row and col
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-30">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                index
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                cbind
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-v">
                N
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-31">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-32">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # number of input features
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-33">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                ncol
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-34">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # number of categories for classification
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-35">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                length
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                unique
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-36">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-37">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-38">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # create and init weights and bias
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-39">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.01
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                rnorm
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                sd
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                0.5
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-40">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-41">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-42">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.01
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                rnorm
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                sd
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                0.5
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-43">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                matrix
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nrow
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ncol
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-44">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-45">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # use all train data to update weights since it's a small dataset
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-46">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                batchsize
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                N
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-47">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-48">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # Training the network
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-49">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-50">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                while
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                maxit
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ||
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                loss
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                abstol
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-51">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-52">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # iteration index
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-53">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-cn">
                1
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-54">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-55">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # forward ....
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-56">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 1 indicate row, 2 indicate col
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-57">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sweep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                W1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '+'
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-58">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # neurons : ReLU
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-59">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pmax
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-60">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sweep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '+'
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-61">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-62">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # softmax
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-63">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                exp
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                exp
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-64">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                probs
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-e">
                sweep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                exp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                rowSums
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                score
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                exp
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '/'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-65">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-66">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # compute the loss
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-67">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                corect
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                logprobs
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-e">
                log
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                probs
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                index
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-68">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                loss
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sum
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                corect
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                logprobs
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-e">
                batchsize
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-69">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                reg
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                loss
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.5
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-v">
                reg
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                sum
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sum
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-70">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                loss
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                loss
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                reg
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                loss
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-71">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-72">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # display results and update model
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-73">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                display
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-74">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-o">
                !
               </span>
               <span class="crayon-st">
                is
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-t">
                null
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                testdata
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-75">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                list
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-76">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-77">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-78">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # weights and bias
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-79">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-80">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-81">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-82">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-83">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labs
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                predict
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dnn
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                testdata
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-84">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                accuracy
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                mean
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-st">
                as
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-t">
                integer
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                testdata
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labs
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-85">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                cat
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                loss
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                accuracy
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "\n"
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-86">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                else
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-87">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                cat
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                loss
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "\n"
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-88">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-89">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-90">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-91">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # backward ....
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-92">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dscores
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                probs
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-93">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                dscores
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                index
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dscores
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                index
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-94">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dscores
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dscores
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                batchsize
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-95">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-96">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                dW2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t ">
                t
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                dscores
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-97">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                db2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                colSums
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                dscores
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-98">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-99">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dhidden
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dscores
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t ">
                t
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-100">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dhidden
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                layer
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;=
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-101">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-102">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dW1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t ">
                t
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                dhidden
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-103">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                db1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                colSums
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                dhidden
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-104">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-105">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # update ....
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-106">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dW2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dW2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                reg
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-e">
                W2
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-107">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                dW1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                dW1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                reg
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-e">
                W1
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-108">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-109">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                lr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                dW1
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-110">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                lr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                db1
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-111">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-112">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                lr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                dW2
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-113">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                lr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                db2
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-114">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-115">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-116">
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-117">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # final results
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-118">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # creat list to store learned parameters
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-119">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # you can add more parameters for debug and visualization
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-120">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # such as residuals, fitted.values ...
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-121">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                list
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                D
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-122">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                H
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-123">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                K
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-124">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # weights and bias
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-125">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-126">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-127">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                W2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-128">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                b2
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-129">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16def95580327420-130">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16def95580327420-131">
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.1527 seconds] -->
       <p>
       </p>
       <p>
        <strong>
         测试和可视化
        </strong>
       </p>
       <p>
        我们已经建立了简单的二层DNN模型，现在我们可以测试我们的模型了。首先将数据集分为训练和测试的两个部分，然后利用训练集训练模型，测试集来测量模型的泛化能力。
       </p>
       <p>
       </p>
       <p>
        其R 代码为：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16defa0526113718" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          ########################################################################
# testing
#######################################################################
set.seed(1)
 
# 0. EDA
summary(iris)
plot(iris)
 
# 1. split data into test/train
samp &lt;- c(sample(1:50,25), sample(51:100,25), sample(101:150,25))
 
# 2. train model
ir.model &lt;- train.dnn(x=1:4, y=5, traindata=iris[samp,], testdata=iris[-samp,], hidden=6, maxit=2000, display=50)
 
# 3. prediction
labels.dnn &lt;- predict.dnn(ir.model, iris[-samp, -5])
 
# 4. verify the results
table(iris[-samp,5], labels.dnn)
#          labels.dnn
#            1  2  3
#setosa     25  0  0
#versicolor  0 24  1
#virginica   0  0 25
 
#accuracy
mean(as.integer(iris[-samp, 5]) == labels.dnn)
# 0.98
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-22">
               22
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-23">
               23
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-24">
               24
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-25">
               25
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-26">
               26
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-27">
               27
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa0526113718-28">
               28
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa0526113718-29">
               29
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16defa0526113718-1">
               <span class="crayon-c">
                ########################################################################
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-2">
               <span class="crayon-c">
                # testing
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-3">
               <span class="crayon-c">
                #######################################################################
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-4">
               <span class="crayon-v">
                set
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                seed
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-5">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-6">
               <span class="crayon-c">
                # 0. EDA
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-7">
               <span class="crayon-e">
                summary
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-8">
               <span class="crayon-e">
                plot
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-9">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-10">
               <span class="crayon-c">
                # 1. split data into test/train
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-11">
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                c
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                sample
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                25
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sample
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                51
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                100
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                25
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sample
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                101
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                150
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                25
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-12">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-13">
               <span class="crayon-c">
                # 2. train model
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-14">
               <span class="crayon-v">
                ir
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                train
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dnn
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                4
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                5
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                traindata
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                testdata
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                maxit
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                2000
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                display
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-15">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-16">
               <span class="crayon-c">
                # 3. prediction
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-17">
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                dnn
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                predict
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dnn
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                ir
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                5
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-18">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-19">
               <span class="crayon-c">
                # 4. verify the results
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-20">
               <span class="crayon-e">
                table
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                5
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                dnn
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-21">
               <span class="crayon-c">
                #          labels.dnn
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-22">
               <span class="crayon-c">
                #            1  2  3
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-23">
               <span class="crayon-c">
                #setosa     25  0  0
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-24">
               <span class="crayon-c">
                #versicolor  0 24  1
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-25">
               <span class="crayon-c">
                #virginica   0  0 25
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-26">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-27">
               <span class="crayon-c">
                #accuracy
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa0526113718-28">
               <span class="crayon-e">
                mean
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-st">
                as
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-t">
                integer
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                iris
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                5
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                dnn
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa0526113718-29">
               <span class="crayon-c">
                # 0.98
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0308 seconds] -->
       <p>
       </p>
       <p>
        在测试设定中的数据丢失和测试精度如下所示：
       </p>
       <p>
        <img src="http://www.parallelr.com/wp-content/uploads/2016/02/iris_loss_accuracy-1.png"/>
       </p>
       <p>
        然后我们比较我们的DNN模型和“nnet”包，代码如下：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685d16defa8428393367" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           R
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          library(nnet)
ird &lt;- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),
                  species = factor(c(rep("s",50), rep("c", 50), rep("v", 50))))
ir.nn2 &lt;- nnet(species ~ ., data = ird, subset = samp, size = 6, rang = 0.1,
               decay = 1e-2, maxit = 2000)
 
labels.nnet &lt;- predict(ir.nn2, ird[-samp,], type="class")
table(ird$species[-samp], labels.nnet)
#  labels.nnet
#   c  s  v
#c 22  0  3
#s  0 25  0
#v  3  0 22
 
# accuracy
mean(ird$species[-samp] == labels.nnet)
# 0.96
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685d16defa8428393367-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57685d16defa8428393367-17">
               17
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685d16defa8428393367-1">
               <span class="crayon-r">
                library
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                nnet
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-2">
               <span class="crayon-v">
                ird
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                frame
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                rbind
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                iris3
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                iris3
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                iris3
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                species
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                factor
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                c
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                rep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "s"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                rep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "c"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                rep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "v"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-4">
               <span class="crayon-v">
                ir
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                nn2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                nnet
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                species
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ~
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ird
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                subset
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                size
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                rang
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.1
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                decay
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1e
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                maxit
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2000
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-6">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-7">
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                nnet
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                predict
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                ir
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                nn2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ird
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                type
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-s">
                "class"
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-8">
               <span class="crayon-e">
                table
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                ird
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-v">
                species
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                nnet
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-9">
               <span class="crayon-c">
                #  labels.nnet
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-10">
               <span class="crayon-c">
                #   c  s  v
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-11">
               <span class="crayon-c">
                #c 22  0  3
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-12">
               <span class="crayon-c">
                #s  0 25  0
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-13">
               <span class="crayon-c">
                #v  3  0 22
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-14">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-15">
               <span class="crayon-c">
                # accuracy
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685d16defa8428393367-16">
               <span class="crayon-e">
                mean
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                ird
               </span>
               <span class="crayon-sy">
                $
               </span>
               <span class="crayon-v">
                species
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                samp
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labels
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                nnet
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57685d16defa8428393367-17">
               <span class="crayon-c">
                # 0.96
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0291 seconds] -->
       <p>
       </p>
       <p>
        <strong class="r geshifilter-R ">
         总结
        </strong>
       </p>
       <p>
        在这篇文章中，我们已经展示了如何实现从零开始的神经网络。但是代码只是实现了DNN的核心概念，读者可以做进一步的实践：
       </p>
       <p>
        解决其他分类问题，如
        <a href="http://www.wildml.com/2015/09/implementing-a-neural-network-from-scratch/">
         玩具箱
        </a>
       </p>
       <p>
        选择不同的隐藏层大小，激活函数，损失函数
       </p>
       <p>
        扩展单隐层网络到多隐层
       </p>
       <p>
        调整网络解决回归问题
       </p>
       <p>
       </p>
       <p>
        <strong>
         在接下来的文章中，我将介绍如何通过多核CPU和NVIDIA GPU为这个代码加速。
        </strong>
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/24678.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/20140917125452915416-216x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24678.html" rel="bookmark" title="python3中的正则模块">
         python3中的正则模块
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24675.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/t015b337bd75d9ef893-161x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24675.html" rel="bookmark" title="注释是恶魔，请不要再写一行注释">
         注释是恶魔，请不要再写一行注释
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24660.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/u16130037972892789947fm21gp0-300x157.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24660.html" rel="bookmark" title="如何从Github上轻松安装R包">
         如何从Github上轻松安装R包
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24654.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/df53fac99fc53ba5a90666abcca25e6d_b-267x200.png"/>
        </a>
        <a class="link" href="http://dataunion.org/24654.html" rel="bookmark" title="简单形象又有趣地说说强大的神经网络">
         简单形象又有趣地说说强大的神经网络
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F22141.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/22141.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/22141.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>